package com.itheima.edu.info.manager.factory;

import com.itheima.edu.info.manager.dao.BaseStudentDao;
import com.itheima.edu.info.manager.dao.OtherStudentDao;

import javax.print.attribute.standard.MediaSize;
import java.io.IOException;
import java.util.Enumeration;
import java.util.Properties;
import java.util.ResourceBundle;

/*
    学生库管工厂类:
        核心职责: 专门对外提供学生库管对象
 */
public class StudentFactory {

    //注意: 当方法的返回值类型是一个接口类型时,方法中需要返回的是该接口的实现类对象
    public static BaseStudentDao getStudentDao1() {
        try {
            ResourceBundle bundle = ResourceBundle.getBundle("prop");
            Class clazz = Class.forName(bundle.getString("studentName"));
            return(BaseStudentDao) clazz.newInstance();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    public static BaseStudentDao getStudentDao() {
        try {
            //1.使用properties读取配置信息
            Properties prop = new Properties();
            prop.load(StudentFactory.class.getClassLoader().getResourceAsStream("prop.properties"));
            //1.反射获取类对象
            Class clazz = Class.forName(prop.getProperty("studentName"));
            return(OtherStudentDao) clazz.newInstance();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return  null;
    }
}
